package com.cherry.javaee.test;

import com.cherry.javaee.demo.domain.User;
import com.cherry.javaee.demo.service.IUserService;
import config.SpringBaseConfig;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.List;


public class UserServiceTest1 {

    @Test
    public void testFindAll() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringBaseConfig.class);
        IUserService userService = context.getBean("userService", IUserService.class);
        List<User> list = userService.findAllUser();
        for (User user : list) {
            System.out.println(user);
        }
    }

    @Test
    public void testFindUser() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringBaseConfig.class);
        IUserService userService = context.getBean("userService", IUserService.class);
        System.out.println(userService.findUser(1L));
    }

    @Test
    public void testAddUser() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringBaseConfig.class);
        IUserService userService = context.getBean("userService", IUserService.class);
        userService.saveUser(new User("添加" + Math.random() * 100 + 1, "添加" + Math.random() * 100 + 100));
    }

    @Test
    public void testUpdateUser() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringBaseConfig.class);
        IUserService userService = context.getBean("userService", IUserService.class);
        userService.update(new User(1L, "更新name", "更新password"));
    }

    @Test
    public void testDeleteUser() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringBaseConfig.class);
        IUserService userService = context.getBean("userService", IUserService.class);
        userService.deleteUser(3L);
    }

}
